<?php

class BaseAjaxModule extends Joob_Controller_Task {
	
	protected $user;
	
	public function init()	{
		$this->view = new Joob_View_Ajax();
		$this->addFilter(new Joob_Filter_NoHtml());
		$this->setupUser();
	}
	
	public function getUser()	{
		return $this->user;
	}
	
	public function setupUser()	{
		$this->user = null;
		$session = Joob_Session_Standard::getInstance();
		$session->setBehaviour(new Joob_Session_Behaviour_Namespace(null, 'Joob:Auth'));
		$userID = $session->get('id');
		if ($userID == null)
			return;
		$user = new Model_User();
		$user->id = $userID;
		if ($user->connect())	{
			$this->user = $user;
		}
		return;
	}
	
	public function postDispatch()	{
		echo $this->view->renderAjax();
	}
	
	public function createErrorResult($msg)	{
		return array('result'=>'error', 'msg'=>$msg);
	}
}

?>